﻿using Microsoft.AspNetCore.Mvc;
using SIMS.Shared.DTO;
using SIMS.WebApi.Models;
using SIMS.WebApi.Services.Score;

namespace SIMS.WebApi.Controllers
{
    /// <summary>
    /// 成绩控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ScoreController : ControllerBase
    {
        private readonly ILogger<ScoreController> logger;

        private readonly IScoreAppService _service;

        public ScoreController(ILogger<ScoreController> logger, IScoreAppService service)
        {
            this.logger = logger;
            this._service = service;
        }

        /// <summary>
        /// 获取成绩信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetScores(string? studentName, string? courseName, int pageNum, int pageSize)
        {
            var data = _service.GetScores(studentName, courseName, pageNum, pageSize);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 获取成绩信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetScore(int id)
        {
            var data = _service.GetScore(id);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 新增成绩
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddScore(ScoreDTO score)
        {
            var data = _service.AddScore(score);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 修改成绩
        /// </summary>
        /// <param name="score"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdateScore(ScoreDTO score)
        {
            var data = _service.UpdateScore(score);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }

        /// <summary>
        /// 删除成绩
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public IActionResult DeleteScore(int id)
        {
            var data = _service.DeleteScore(id);

            var res = new ResultModel();
            res.code = 1;
            res.msg = "success";
            res.data = data;
            return Ok(res);
        }
    }
}
